import {takeEvery, put} from 'redux-saga/effects';
import {GET_INIT_LIST} from './actionTypes';
import {getInitialListAction} from './actionCreators';
import axios from "axios";

function* getInitList() {

    try {
        const res = yield axios.get('https://www.peppaex.com/m/currency');

        let datas = res.data.datas;
        let currencyArr = [];
        for(let i = 0; i < datas.length; i++){
            currencyArr.push(datas[i].currency)
        }

        const action = getInitialListAction(currencyArr);
        yield put(action);
    } catch (e) {
        console.log('请求失败')
    }


}

// generator函数
function* mySaga() {
    yield takeEvery(GET_INIT_LIST, getInitList);
}

export default mySaga;